package com.yanqu.road.server.cmd.activity.pawnshop;

import com.yanqu.road.entity.enums.activity.pawnshop.ePawnshopWay;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.PawnshopProto.PawnshopEventMoneyConfirmRespMsg;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.pawnshop.PawnshopModule;
import com.yanqu.road.server.manger.activity.pawnshop.PawnshopMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_PAWNSHOP_EVENT_MONEY_CONFIRM, desc = "请求送钱事件确认")
public class PawnshopEventMoneyConfirmCmd extends AbstractCommand {

	private long coinReward = 0;// 确认后获得的当铺币
	
	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if (!PawnshopMgr.isActivityInTime()) {
			// 非活动时间内
			this.ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
		PawnshopModule psModule = player.getModule(PawnshopModule.class);
		if (!psModule.getUserPawnshop().isReception()) {
			// 顾客未接待过
			this.ret = GameErrorCode.E_PAWNSHOP_NOT_RECEPTION;
			return;
		}
		// 确认成功
		coinReward = psModule.getUserPawnshopEvent().getMoney().getMoney();
		psModule.coinReward(coinReward, eLogMoneyType.PawnshopMoneyReward.getValue());
		player.getModule(PawnshopModule.class).afterReception();
	}

	@Override
	public void sendData(GamePlayer player) {
		PawnshopEventMoneyConfirmRespMsg.Builder builder = PawnshopEventMoneyConfirmRespMsg.newBuilder();
		builder.setRet(ret);
		if (ret == 0) {
			builder.setCoinReward(coinReward);
		}
		player.sendPacket(ClientProtocol.U_PAWNSHOP_EVENT_MONEY_CONFIRM, builder);
	}
}
